package com.shelpe.services.sinbad.dto.semiauto;

import org.apache.commons.lang3.math.NumberUtils;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Data;

@Data
public class SemiautoCondition {
	public final static String METHOD_AND = "and";
	public final static String METHOD_OR = "or";
	
	public final static String CONDITION_GREATER = ">";
	public final static String CONDITION_LESS = "<";
	public final static String CONDITION_EQUAL = "=";
	public final static String CONDITION_GREATER_EQUAL = ">=";
	public final static String CONDITION_LESS_EQUAL = "<=";
	
	public final static int SOURCE_TYPE_AVERAGE = 1;
	public final static int SOURCE_TYPE_MAX = 2;
	public final static int SOURCE_TYPE_AVERAGE_INDUSTRY = 4;
	public final static int SOURCE_TYPE_CUSTOM = 3;
	
	private String name;
	private String condition;
	private int depth;
	@JsonProperty("source_type")
	private int sourceType;
	@JsonProperty("source_value")
	private String sourceValue;
	private int value;
	private String method;
	
	
	public boolean runCondition(float metric){
		boolean res = false;
		switch(this.condition){
		
		case CONDITION_GREATER:
			res = ((metric/value) > NumberUtils.toFloat(this.sourceValue, 0)); 
			break;
		case CONDITION_LESS:
			res = ((metric/value) < NumberUtils.toFloat(this.sourceValue, 0));
			break;
		case CONDITION_GREATER_EQUAL:
			res = ((metric/value) >= NumberUtils.toFloat(this.sourceValue, 0));
			break;
		case CONDITION_LESS_EQUAL:
			res = ((metric/value) <= NumberUtils.toFloat(this.sourceValue, 0));
			break;
		default:
			res = ((metric/value) == NumberUtils.toFloat(this.sourceValue, 0));
		}
		
		return res;
	}
}
